package com.wenhao.leetcode.medium;

/**
 *
 * @author Wenhao Tong
 * @date 2021/6/28 下午9:42
 */
public class LeetCode48 {
    public static void main(String[] args) {
        LeetCode48 leetCode48 = new LeetCode48();
        int[][] matrix = new int[][]{
                {1,2,3},
                {4,5,6},
                {7,8,9}
        };
        leetCode48.rotate(matrix);
        for (int[] row : matrix) {
            for (int i : row) {
                System.out.print(i);
            }
            System.out.println();
        }
    }

    public void rotate(int[][] matrix) {
        int length = matrix.length;
        for (int i = 0;i < length / 2;i++) {
            for (int j = 0;j < (length + 1) / 2;j++) {
                int temp = matrix[i][j];
                matrix[i][j] = matrix[length - 1 - j][i];
                matrix[length - 1 - j][i] = matrix[length - 1 - i][length - 1 - j];
                matrix[length - 1 - i][length - 1 - j] = matrix[j][length - 1 - i];
                matrix[j][length - 1 - i] = temp;
            }
        }
    }
}
